package com.jemframework.domain;

import java.util.HashMap;
import java.util.Map;

import com.jemframework.Initializable;

public abstract class AbstractEntityTypeNameMapping implements EntityTypeNameMapping, Initializable {

  private Map<Integer, String> iEntityTypeNameMapping = new HashMap<Integer, String>();
  private Map<String, Integer> iEntityTypeMapping = new HashMap<String, Integer>();

  public AbstractEntityTypeNameMapping() {
    initialize();
  }

  public abstract void initialize();

  protected void map(int anEntityType, String anEntityTypeName) {
    iEntityTypeNameMapping.put(anEntityType, anEntityTypeName);
    iEntityTypeMapping.put(anEntityTypeName, anEntityType);
  }

  public int getEntityType(String anEntityName) {
    Integer theEntityType = iEntityTypeMapping.get(anEntityName);
    if (theEntityType == null) {
      throw new IllegalArgumentException("Unknown entity type name: " + anEntityName);
    }
    return theEntityType;
  }

  public String getEntityTypeName(int anEntityType) {
    String theEntityTypeName = iEntityTypeNameMapping.get(anEntityType);
    if (theEntityTypeName == null) {
      throw new IllegalArgumentException("Unknown entity type: " + anEntityType);
    }
    return theEntityTypeName;
  }

}
